package model

import (
	"evaluation/global"
	"gorm.io/gorm"
	"time"
)

type Banned struct {
	Id        uint32         `gorm:"column:id;type:int UNSIGNED;comment:敏感词ID;primaryKey;not null;" form:"id" json:"id"`                                          // 敏感词ID
	Banned    string         `gorm:"column:banned;type:varchar(255);comment:敏感词内容;not null;" form:"banned" json:"banned"`                                       // 敏感词内容
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);comment:添加时间;not null;default:CURRENT_TIMESTAMP(3);" form:"created_at" json:"created_at"` // 添加时间
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);comment:修改时间;not null;default:CURRENT_TIMESTAMP(3);" form:"updated_at" json:"updated_at"` // 修改时间
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);comment:删除时间;default:NULL;" form:"deleted_at" json:"deleted_at"`                          // 删除时间
}

func (b *Banned) TableName() string {
	return "banned"
}

func (b *Banned) AddBanned() error {
	return global.DB.Create(&b).Error
}

func (b *Banned) UpdatedBanned() error {
	return global.DB.Updates(&b).Error
}

func (b *Banned) DeletedBanned() error {
	return global.DB.Where("id = ?", b.Id).Delete(&b).Error
}

func (b *Banned) GetBanned() error {
	return global.DB.Where("banned like ?", "%"+b.Banned+"%").Find(&b).Error
}
